package com.zzyl.service.impl;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.entity.NursingLevel;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.service.NursingLevelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NursingLevelServiceImpl implements NursingLevelService {

    @Autowired
    private NursingLevelMapper nursingLevelMapper;

    /**
     * 查询所有
     * @return
     */
    @Override
    public List<NursingLevel> list() {
        return nursingLevelMapper.listAll();
    }

    /**
     * 添加
     * @param nursingLevel
     */
    @Override
    public void insert(NursingLevel nursingLevel) {
        nursingLevelMapper.insert(nursingLevel);
    }

    /**
     * 分页查询
     * @param pageNum
     * @param pageSize
     * @param name
     * @param status
     * @return
     */
    @Override
    public PageResponse<NursingLevel> getByPage(Integer pageNum, Integer pageSize, String name, Byte status) {
        PageHelper.startPage(pageNum, pageSize);
        Page<NursingLevel> list = nursingLevelMapper.selectPage(name, status);
        PageResponse<NursingLevel> result = PageResponse.of(list, NursingLevel.class);
        return result;
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @Override
    public NursingLevel selectById(Long id) {
        NursingLevel nursingLevel =   nursingLevelMapper.selectByIdId(id);
        return nursingLevel;
    }

    /**
     * 根据id修改
     * @param nursingLevel
     */
    @Override
    public void update(NursingLevel nursingLevel) {
      nursingLevelMapper.update(nursingLevel);
    }

    /**
     * 根据id删除
     * @param id
     */
    @Override
    public void deleteById(Long id) {
        nursingLevelMapper.deleteById(id);
    }

    /**
     * 更改状态
     * @param id
     * @param status
     */
    @Override
    public void updateStatus(Long id, Byte status) {
        NursingLevel nursingLevel = new NursingLevel();
        nursingLevel.setId(id);
        nursingLevel.setStatus(status);
        nursingLevelMapper.update(nursingLevel);
    }
}